<?php

namespace App\Services;
/**
 * 基础业务类
 *
 * @author WangBin
 * @date 2021-09-24
 * @package App\Http\Services
 */
class BaseService
{
    protected static $instance = [];

    /**
     * @return static
     */
    public static function getInstance()
    {
        if((static::$instance[static::class] ?? []) instanceof static) {
            return static::$instance[static::class];
        }
        return static::$instance[static::class] = new static();
    }

    /**
     * 返回分页列表数据
     *
     * @param $data
     * @param $page
     * @param $pageSize
     * @return array
     */
    public function toList($data, $page, $pageSize)
    {
        return ['total' => $data->count(), 'list' => $data->offset($page * $pageSize)->limit($pageSize)->get()];
    }

    /**
     * 返回列表数据
     *
     * @param $data
     * @param $page
     * @param $pageSize
     * @return array
     */
    public function toSimpleList($data)
    {
        return ['list' => $data->get()];
    }

    private function __construct(){}
    private function __clone(){}
}
